import React, { Component } from 'react'

class Login extends Component {

    state = {
        user: ''
    }

    setUser = (e) => {
        this.setState({
            user: e.target.value
        })
    }

    setUserData() {
        localStorage.setItem('user', JSON.stringify(this.state.user))

        this.props.history.push(`/home/my${this.state.user}`)
    }

    render() { 
        let { user } = this.state
        return (
            <div>
                <input defaultValue={user} placeholder='请输入用户名' onChange={
                    e => this.setUser(e)
                } />
                <button onClick={
                    this.setUserData.bind(this)
                }>登录</button>
            </div>
        )
    }
}
 
export default Login